%23%20%2F%2F%2F%20script%0A%23%20requires-python%20%3D%20%22%3E%3D3.13%22%0A%23%20dependencies%20%3D%20%5B%0A%23%20%20%20%20%20%22kaleido%3D%3D1.2.0%22%2C%0A%23%20%20%20%20%20%22marimo%22%2C%0A%23%20%20%20%20%20%22matplotlib%3D%3D3.10.8%22%2C%0A%23%20%20%20%20%20%22numpy%3D%3D2.4.1%22%2C%0A%23%20%20%20%20%20%22pandas%3D%3D3.0.0%22%2C%0A%23%20%20%20%20%20%22plotly%3D%3D6.5.2%22%2C%0A%23%20%20%20%20%20%22scipy%3D%3D1.17.0%22%2C%0A%23%20%5D%0A%23%20%2F%2F%2F%0A%0Aimport%20marimo%0A%0A__generated_with%20%3D%20%220.19.6%22%0Aapp%20%3D%20marimo.App(width%3D%22medium%22)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.hstack(%0A%20%20%20%20%20%20%20%20%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20mo.image(%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20src%3D%22http%3A%2F%2Fmodernmacro.org%2Fresources%2FVivaldo%2Ffigures%2FOldTests%2FRIR.png%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20width%3D200%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20mo.image(%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20src%3D%22http%3A%2F%2Fmodernmacro.org%2Fresources%2FVivaldo%2Ffigures%2Fiscte.png%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20width%3D300%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20)%2C%0A%20%20%20%20%20%20%20%20%5D%2C%0A%20%20%20%20%20%20%20%20align%3D%22center%22%2C%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%20Day%201%20-%20Welcome%20to%20Marimo%20Notebooks%0A%0A%20%20%20%20%23%23%20Introduction%20to%20Marimo%0A%20%20%20%20%3Cbr%3E%0A%20%20%20%20**Vivaldo%20Mendes**%0A%0A%20%20%20%20**February%2002%2C%202026**%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%3Cstyle%3E%0A%20%20%20%20.marimo-cell%20%7B%0A%20%20%20%20%20%20%20%20border%3A%20none%20!important%3B%0A%20%20%20%20%20%20%20%20box-shadow%3A%20none%20!important%3B%0A%20%20%20%20%20%20%20%20margin%3A%200%20!important%3B%0A%20%20%20%20%20%20%20%20padding%3A%200%20!important%3B%0A%20%20%20%20%7D%0A%0A%20%20%20%20.marimo-cell-content%20%7B%0A%20%20%20%20%20%20%20%20padding%3A%200.5rem%200%20!important%3B%0A%20%20%20%20%7D%0A%20%20%20%20.admonition%20%7B%0A%20%20%20%20margin-top%3A%20-0.99rem%20!important%3B%0A%20%20%20%20margin-bottom%3A%20-0.99rem%20!important%3B%0A%20%20%20%20%7D%0A%20%20%20%20h1%20%7B%0A%20%20%20%20%20%20%20%20margin-bottom%3A%20-1.2rem%20!important%3B%0A%20%20%20%20%7D%0A%20%20%20%20h2%20%7B%0A%20%20%20%20%20%20%20%20margin-bottom%3A%20-1.2rem%20!important%3B%0A%20%20%20%20%7D%0A%20%20%20%20%2F*%20Reduce%20spacing%20before%20bullet%20lists%20*%2F%0A%20%20%20%20ul%20%7B%0A%20%20%20%20%20%20%20%20margin-top%3A%20-0.3rem%20!important%3B%0A%20%20%20%20%7D%0A%20%20%20%20%2F*%20Optionally%20reduce%20spacing%20between%20list%20items%20*%2F%0A%20%20%20%20li%20%7B%0A%20%20%20%20%20%20%20%20margin-bottom%3A%200.2rem%20!important%3B%0A%20%20%20%20%7D%0A%20%20%20%20%2F*%20Increase%20font%20size%20for%20all%20text%20in%20the%20document%20*%2F%0A%20%20%20%20body%20%7B%0A%20%20%20%20%20%20%20%20font-size%3A%2016px%3B%0A%20%20%20%20%7D%0A%0A%20%20%20%20%2F*%20Increase%20font%20size%20for%20all%20headers%20*%2F%0A%20%20%20%20h1%20%7B%0A%20%20%20%20%20%20%20%20font-size%3A%2036px%20!important%3B%0A%20%20%20%20%7D%0A%0A%20%20%20%20h2%20%7B%0A%20%20%20%20%20%20%20%20font-size%3A%2028px%20!important%3B%0A%20%20%20%20%7D%0A%0A%20%20%20%20h3%20%7B%0A%20%20%20%20%20%20%20%20font-size%3A%2025px%20!important%3B%0A%20%20%20%20%7D%0A%20%20%20%20%3C%2Fstyle%3E%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%22%22%22%0A%20%20%20%20---%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20Libraries%20used%20in%20this%20notebook%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20import%20marimo%20as%20mo%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%23%20Reactive%20Python%20notebooks%0A%20%20%20%20import%20numpy%20as%20np%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%23%20Numerical%20computing%0A%20%20%20%20import%20pandas%20as%20pd%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%23%20Data%20manipulation%0A%20%20%20%20from%20scipy.optimize%20import%20fsolve%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%23%20Scientific%20computing%0A%20%20%20%20import%20plotly.graph_objects%20as%20go%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%23%20Interactive%20plotting%0A%20%20%20%20from%20plotly.subplots%20import%20make_subplots%0A%20%20%20%20import%20plotly.express%20as%20px%0A%20%20%20%20import%20plotly.io%20as%20pio%20%0A%20%20%20%20pio.templates.default%20%3D%20%22plotly%22%0A%20%20%20%20import%20kaleido%0A%20%20%20%20pio.defaults.default_format%20%3D%20%22svg%22%0A%20%20%20%20from%20datetime%20import%20datetime%0A%20%20%20%20import%20warnings%0A%20%20%20%20warnings.filterwarnings('ignore')%0A%20%20%20%20import%20os%0A%20%20%20%20os.chdir(os.path.dirname(__file__))%0A%20%20%20%20return%20fsolve%2C%20go%2C%20mo%2C%20np%2C%20os%2C%20pd%2C%20px%0A%0A%0A%40app.cell%0Adef%20_(os)%3A%0A%20%20%20%20%23import%20os%0A%20%20%20%20os.getcwd()%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%22%22%22%0A%20%20%20%20---%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%201.%20What%20is%20a%20Marimo%20notebook%3F%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20A%20notebook%20is%20a%20document%20with%20two%20types%20of%20cells%20(see%20image%20below)%3A%0A%20%20%20%20-%20**Code%20cells**%20-%20contain%20Python%20code%20that%20can%20be%20executed%0A%20%20%20%20-%20**Markdown%20cells**%20-%20contain%20formatted%20text%2C%20mathematics%2C%20images%2C%20and%20more%0A%0A%20%20%20%20The%20versatility%20that%20arises%20from%20combining%20markdown%20cells%20with%20code%20cells%20makes%20notebooks%20a%20remarkable%20tool%20for%20computational%20work%20in%20general%20and%20teaching%20in%20particular.%0A%0A%20%20%20%20Marimo%20notebooks%20are%20**reactive**%3A%20when%20you%20change%20a%20cell%2C%20all%20cells%20that%20depend%20on%20it%20automatically%20re-run.%20This%20ensures%20your%20notebook%20is%20always%20in%20a%20consistent%20state.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.Html(%22%22%22%0A%20%20%20%20%3Cdiv%20style%3D%22display%3A%20flex%3B%20justify-content%3A%20left%3B%20align-items%3A%20left%3B%22%3E%0A%20%20%20%20%20%20%20%20%3Cimg%20%0A%20%20%20%20%09%09src%3D%22http%3A%2F%2Fmodernmacro.org%2Fresources%2FVivaldo%2Ffigures%2FMarimo%2Fmarimo_cells.png%22%20%0A%20%20%20%20%09alt%3D%22Centered%20Image%22%20style%3D%22max-width%3A%2070%25%3B%20height%3A%20auto%3B%22%3E%0A%20%20%20%20%3C%2Fdiv%3E%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%22%22%22%0A%20%20%20%20---%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%202.%20Marimo%20basic%20tips%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%23%20Creating%20and%20running%20cells%0A%0A%20%20%20%20-%20Put%20the%20mouse%20on%20top%20of%20any%20opened%2Fvisible%20cell.%0A%20%20%20%20-%20You%20will%20see%20a%20%3Ckbd%3E%2B%3C%2Fkbd%3E%20sign%20in%20the%20top%20and%20bottom%20left%20corners%20(**_see%20image%20below_**).%0A%20%20%20%20-%20Click%20on%20the%20%3Ckbd%3E%2B%3C%2Fkbd%3E%20sign%20where%20you%20want%20the%20new%20cell%20to%20be%20placed.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.Html(%22%22%22%0A%20%20%20%20%3Cdiv%20style%3D%22display%3A%20flex%3B%20justify-content%3A%20left%3B%20align-items%3A%20left%3B%22%3E%0A%20%20%20%20%20%20%20%20%3Cimg%20%0A%20%20%20%20%09%09src%3D%22http%3A%2F%2Fmodernmacro.org%2Fresources%2FVivaldo%2Ffigures%2FMarimo%2Fmarimo_newcells.png%22%20%0A%20%20%20%20%09alt%3D%22Centered%20Image%22%20style%3D%22max-width%3A%2070%25%3B%20height%3A%20auto%3B%22%3E%0A%20%20%20%20%3C%2Fdiv%3E%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%23%20How%20to%20run%20a%20cell%3F%0A%0A%20%20%20%20-%20See%20**_image%20above_**%0A%20%20%20%20-%20Click%20on%20the%20small%20circle-arrow%20in%20the%20top%20right-hand-side%20of%20each%20cell%3A%20%3Ckbd%3E%E2%96%B6%EF%B8%8F%3C%2Fkbd%3E%0A%20%20%20%20-%20Or%2C%20click%20simultaneosly%20on%20%3Ckbd%3ECtrl%3C%2Fkbd%3E%20%3Ckbd%3E%E2%86%A9%20Enter%3C%2Fkbd%3E%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%23%20How%20to%20save%20a%20notebook%3F%0A%0A%20%20%20%20-%20When%20a%20cell%20is%20run%2C%20this%20action%20will%20be%20automatically%20saved%0A%20%20%20%20-%20If%20we%20forget%20to%20run%20a%20particular%20cell%2C%20click%20simultaneously%20on%20%3Ckbd%3ECtrl%3C%2Fkbd%3E%20%3Ckbd%3EShift%3C%2Fkbd%3E%20%3Ckbd%3ER%3C%2Fkbd%3E%20to%20save%20all%20changes%20that%20may%20have%20been%20implemented%20and%20not%20yet%20saved.%20There%20is%20also%20a%20button%20to%20save%20all%20stale%20cells%20(cells%20not%20yet%20run)%20at%20the%20bottom%20right%20corner%20of%20the%20notebook%3A%20%3Ckbd%3E%E2%96%B6%3C%2Fkbd%3E%0A%20%20%20%20-%20If%20we%20want%20to%20save%20the%20notebook%2C%20independently%20of%20whether%20all%20the%20cells%20were%20run%20(or%20not)%2C%20click%20simultaneously%20on%20%3Ckbd%3ECtrl%3C%2Fkbd%3E%20%3Ckbd%3ES%3C%2Fkbd%3E%3B%20there%20is%20also%20a%20button%20for%20this%20task%20at%20the%20bottom%20right%20corner%20of%20the%20notebook%3A%20%3Ckbd%3E%F0%9F%92%BE%3C%2Fkbd%3E%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%23%20Code%20cells%0A%20%20%20%20-%20When%20we%20click%20on%20the%20%3Ckbd%3E%2B%3C%2Fkbd%3E%20sign%2C%20as%20shown%20above%2C%20a%20new%20cell%20will%20be%20automatically%20opened%0A%20%20%20%20-%20By%20default%2C%20this%20new%20cell%20will%20be%20a%20code%20cell%0A%20%20%20%20-%20The%20next%20cell%20is%20an%20empty%20code%20cell%20that%20can%20be%20used%20for%20computation.%20For%20example%2C%20type%202%2B2%20and%20run%20it.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%23%20Markdown%20cells%0A%20%20%20%20-%20If%20we%20want%20to%20write%20text%20or%20mathematics%20in%20a%20new%20cell%2C%20or%20insert%20a%20video%2C%20we%20have%20to%20turn%20it%20into%20a%20%22markdown%22%20cell%0A%20%20%20%20-%20To%20change%20a%20cell%20from%20code%20mode%20into%20**_markdown%20mode_**%2C%20put%20the%20cursor%20inside%20the%20cell%20you%20want%20to%20be%20in%20markdown.%0A%20%20%20%20%20%20-%20Click%20simultaneously%20on%20%3Ckbd%3ECtrl%3C%2Fkbd%3E%20%3Ckbd%3EShift%3C%2Fkbd%3E%20%3Ckbd%3EM%3C%2Fkbd%3E%0A%20%20%20%20%20%20-%20...%20or%20you%20can%20click%20on%20the%20**button**%20that%20does%20that%20task%20(see%20image%20above)%3A%20%3Ckbd%3E%E2%93%82%EF%B8%8F%E2%AC%87%3C%2Fkbd%3E%0A%20%20%20%20-%20That%20is%20all.%20You%20can%20start%20typing%20text%20or%20mathematics%20as%20you%20like.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%2F%2F%2F%20tip%20%7C%20Very%20common%20formats%0A%0A%20%20%20%20To%20write%20text%20in%20bold%2C%20italics%2C%20or%20mathematical%20symbols%3A%0A%20%20%20%20-%20Type%3A%20%60**This%20is%20bold**%60%20to%20get%3A%20**This%20is%20bold**%0A%20%20%20%20-%20Type%3A%20%60*This%20is%20italics*%60%20to%20get%3A%20*This%20is%20italics*%0A%20%20%20%20-%20Type%3A%20%60***This%20is%20bold%20and%20italics***%60%20to%20get%3A%20***This%20is%20bold%20and%20italics***%0A%20%20%20%20-%20Type%3A%20%60%24y%3D2x%5E2%24%60%20to%20get%20a%20mathematical%20expression%3A%20%24y%3D2x%5E2%24%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%2F%2F%2F%20tip%20%7C%20Lists%0A%20%20%20%20-%20This%20is%20my%20first%20item%0A%20%20%20%20-%20This%20is%20my%20second%20item%0A%20%20%20%20%20%20-%20Two%20spaces%20give%20my%20first%20sub-item%0A%20%20%20%20%20%20-%20My%20second%0A%20%20%20%20%20%20%20%20-%20Four%20spaces%20give%20first%20sub-sub-item%0A%20%20%20%20%20%20%20%20-%20Very%20easy%0A%20%20%20%20-%20My%20final%20item%0A%0A%20%20%20%201.%20My%20first%20numbered%20item%0A%20%20%20%202.%20Wow%2C%20this%20is%20easy%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%2F%2F%2F%20tip%20%7C%20Mathematical%20text%0A%0A%20%20%20%20To%20write%20mathematical%20expressions%20in%20markdown%2C%20we%20use%20LaTeX%20syntax%20with%20%60%24%60.%0A%0A%20%20%20%20This%20is%20inline%20mathematics%3A%20%24y%3D2x%24.%0A%0A%20%20%20%20This%20is%20displayed%20mathematics%3A%0A%0A%20%20%20%20%24%24y%3D2x%24%24%0A%0A%20%20%20%20This%20is%20mathematics%20using%20the%20power%20syntax%3A%20%24y%20%3D%202x%5E3%24%0A%0A%20%20%20%20This%20is%20mathematics%20using%20the%20fraction%20syntax%3A%20%24h%20%3D%20%5Cfrac%7B3%7D%7B4n%7D%24%0A%0A%20%20%20%20This%20is%20more%20elaborate%20mathematics%3A%20%24z%20%3D%20%5Cint_%7Ba%7D%5E%7Bb%7D%20x%5E2%20dx%24%0A%0A%20%20%20%20This%20is%20using%20Greek%20symbols%20and%20a%20tag%20(1)%3A%0A%0A%20%20%20%20%24%24%5Clambda%20%3D%20%5Csum_%7Bi%3D0%7D%5E%7B%5Cinfty%7D%20%5Calpha%5Ei%20x_%7Bi-1%7D%20%5Ctag%7B1%7D%24%24%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%2F%2F%2F%20tip%20%7C%20Tables%0A%0A%20%20%20%20It%20is%20extremely%20easy%20to%20produce%20a%20table.%20Use%20the%20%60%7C%60%20to%20separate%20columns%20and%20%60%3A%60%20to%20align%20columns%3A%0A%0A%20%20%20%20%7C%20Model%20%20%20%20%20%20%20%7C%20Prompt%20runs%20%7C%20Output%20parsable%20%7C%20Infrastructure%20%7C%20Result%20%7C%0A%20%20%20%20%7C%3A------%20%20%20%20%20%20%7C%3A-----------%3A%7C%3A---------------%3A%7C%3A--------------%3A%7C%3A------%3A%7C%0A%20%20%20%20%7C%20GPT-4o%20%20%20%20%20%7C%20%E2%9C%93%20%20%20%20%20%20%20%20%20%20%20%7C%20%E2%9C%93%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7C%20%E2%9C%93%20%20%20%20%20%20%20%20%20%20%20%20%20%7C%20%E2%9C%85%20Works%20%7C%0A%20%20%20%20%7C%20Gemini%202.0%20%20%7C%20%E2%9C%93%20%20%20%20%20%20%20%20%20%20%20%7C%20%E2%9C%93%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7C%20%E2%9A%A0%EF%B8%8F%20Budget%20%20%20%20%20%7C%20%E2%9A%A0%EF%B8%8F%20Partial%20%7C%0A%20%20%20%20%7C%20Gemma%202%2027B%20%7C%20%E2%9C%93%20%20%20%20%20%20%20%20%20%20%20%7C%20%E2%9C%97%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7C%20%E2%9C%93%20%20%20%20%20%20%20%20%20%20%20%20%20%7C%20%E2%9D%8C%20Format%20%7C%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%F0%9F%91%89%20**Exercise%201**%0A%0A%20%20%20%20-%20Open%20a%20new%20cell.%20Write%20the%20following%20text%3A%20%60Today%20is%20a%20sunny%20day!%60%0A%20%20%20%20-%20Open%20another%20cell%20and%20write%20the%20same%20text%20but%20in%20bold%2C%20and%20also%20in%20italics.%0A%20%20%20%20-%20Open%20a%20new%20cell%20and%20write%3A%20This%20is%20text%20and%20mathematics%20with%20a%20funny%20equation%20%24y%20%3D%20xz%2F2%24%0A%20%20%20%20-%20Open%20a%20new%20cell%20and%20write%20the%20following%20equation%3A%20%24y%20%3D%203x%5E2%24%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%2F%2F%2F%20hint%20%7C%20Answer%3A%20Exercise%201%0A%0A%20%20%20%20Today%20is%20a%20sunny%20day!%0A%0A%20%20%20%20**Today%20is%20a%20sunny%20day!**%0A%0A%20%20%20%20***Today%20is%20a%20sunny%20day!***%0A%0A%20%20%20%20This%20is%20text%20and%20mathematics%20with%20a%20funny%20equation%20%24y%20%3D%20xz%2F2%24%0A%0A%20%20%20%20%24y%20%3D%203x%5E2%24%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%22%22%22%0A%20%20%20%20---%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%203.%20Arithmetic%20operators%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%2F%2F%2F%20danger%20%7C%20Python%20supports%20the%20following%20arithmetic%20operators%3A%0A%0A%20%20%20%20%3Ckbd%3E%2Bx%3C%2Fkbd%3E%20-%20unary%20plus%20(identity%20operation)%20%3Cbr%3E%0A%20%20%20%20%3Ckbd%3E-x%3C%2Fkbd%3E%20-%20unary%20minus%20(negation)%20%3Cbr%3E%0A%20%20%20%20%3Ckbd%3Ex%20%2B%20y%3C%2Fkbd%3E%20-%20addition%20%3Cbr%3E%0A%20%20%20%20%3Ckbd%3Ex%20-%20y%20%3C%2Fkbd%3E%20-%20subtraction%20%3Cbr%3E%0A%20%20%20%20%3Ckbd%3Ex%20*%20y%3C%2Fkbd%3E%20-%20multiplication%20%3Cbr%3E%0A%20%20%20%20%3Ckbd%3Ex%20%2F%20y%3C%2Fkbd%3E%20%20-%20division%20(always%20returns%20float)%20%3Cbr%3E%0A%20%20%20%20%3Ckbd%3Ex%20%2F%2F%20y%3C%2Fkbd%3E%20%20-%20floor%20division%20(integer%20division)%20%3Cbr%3E%0A%20%20%20%20%3Ckbd%3Ex%20%25%20y%3C%2Fkbd%3E%20%20-%20modulus%20(remainder)%20%3Cbr%3E%0A%20%20%20%20%3Ckbd%3Ex%20**%20y%3C%2Fkbd%3E%20%20-%20exponentiation%20(power)%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%202%2B3%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%2010**4%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20pepe%20%3D%2010%0A%20%20%20%20return%20(pepe%2C)%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20rock%20%3D%2020%0A%20%20%20%20return%20(rock%2C)%0A%0A%0A%40app.cell%0Adef%20_(pepe%2C%20rock)%3A%0A%20%20%20%20mary%20%3D%20pepe%20*%20rock%0A%20%20%20%20mary%0A%20%20%20%20return%20(mary%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20fiona_slider%20%3D%20mo.ui.slider(-5.0%2C%205.0%2C%20value%3D1.0%2C%20step%3D0.5%2C%20show_value%3DTrue%2C%20label%3D%22fiona%22)%0A%20%20%20%20fiona_slider%0A%20%20%20%20return%20(fiona_slider%2C)%0A%0A%0A%40app.cell%0Adef%20_(fiona_slider%2C%20mary)%3A%0A%20%20%20%20fiona%20%3D%20fiona_slider.value%0A%20%20%20%20paty%20%3D%20(fiona%20*%20mary%2C%20fiona**2%2C%20fiona%2Fmary%2C%2010*fiona)%0A%20%20%20%20paty%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%F0%9F%91%89%20**Exercise%202**%0A%0A%20%20%20%20What%20is%20the%20value%20of%20a%20variable%20called%20%22zazu%22%2C%20given%20the%20following%20equation%3F%0A%0A%20%20%20%20%24%24zazu%20%3D%2010%20%2B%20rock%5E2%20%2B%20%5Cfrac%7Bpepe%7D%7B2%7D%20%5Ctag%7B2%7D%24%24%0A%0A%20%20%20%20Use%20the%20cell%20below%20to%20obtain%20the%20solution%20to%20equation%20(2).%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(pepe%2C%20rock)%3A%0A%20%20%20%20%23%20Answer%20to%20Exercise%202%0A%20%20%20%20zazu%20%3D%2010%20%2B%20rock**2%20%2B%20pepe%2F2%0A%20%20%20%20zazu%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%2F%2F%2F%20hint%20%7C%20Answer%3A%20Exercise%202%0A%0A%20%20%20%20zazu%20%3D%20415%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%22%22%22%0A%20%20%20%20---%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%204.%20Plotting%20functions%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(np)%3A%0A%20%20%20%20x%20%3D%20np.arange(0.0%2C%2020.0%2C%200.05)%0A%20%20%20%20Ana%20%3D%202%20*%20np.sin(x)%0A%20%20%20%20return%20Ana%2C%20x%0A%0A%0A%40app.cell%0Adef%20_(Ana%2C%20px%2C%20x)%3A%0A%20%20%20%20%23%20Simple%20sine%20wave%20plot%0A%20%20%20%20fig1%20%3D%20px.line(x%3Dx%2C%20y%3DAna)%0A%20%20%20%20fig1.update_layout(height%3D450%2C%20hovermode%3D'x'%2C%20title_text%3D'My%20fancy%20plot'%2C%20title_x%3D0.5%2C%20xaxis_title%20%3D%20%22x%22%2C%20yaxis_title%20%3D%20%22Ana%22%2C%20margin%3Ddict(l%3D70%2C%20r%3D60%2C%20t%3D70%2C%20b%3D60))%0A%20%20%20%20fig1%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(np)%3A%0A%20%20%20%20noise%20%3D%20np.random.randn(500)%0A%20%20%20%20return%20(noise%2C)%0A%0A%0A%40app.cell%0Adef%20_(go%2C%20noise)%3A%0A%20%20%20%20%23%20Histogram%20of%20random%20noise%0A%20%20%20%20fig3%20%3D%20go.Figure()%0A%20%20%20%20fig3.add_trace(go.Histogram(x%3Dnoise%2C%20nbinsx%3D50%2C%20opacity%3D0.75))%0A%20%20%20%20fig3.update_layout(bargap%3D0.05%2C%20height%3D450%2C%20margin%3Ddict(l%3D70%2C%20r%3D60%2C%20t%3D70%2C%20b%3D60))%0A%20%20%20%20fig3%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%F0%9F%91%89%20**Exercise%203**%0A%0A%20%20%20%20In%20the%20following%20cell%2C%20produce%20a%20simple%20plot%20of%20the%20following%20function%3A%20%24e%5E%7BAna%7D%24%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(Ana%2C%20go%2C%20np%2C%20x)%3A%0A%20%20%20%20%23%20Exercise%203%20answer%0A%20%20%20%20fig_exp%20%3D%20go.Figure()%0A%20%20%20%20fig_exp.add_trace(go.Scatter(x%3Dx%2C%20y%3Dnp.exp(Ana)%2C%20mode%3D'lines'))%0A%20%20%20%20fig_exp.update_layout(height%3D450%2C%20margin%3Ddict(l%3D70%2C%20r%3D60%2C%20t%3D70%2C%20b%3D60))%0A%20%20%20%20fig_exp%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%F0%9F%91%89%20**Exercise%204**%0A%0A%20%20%20%20In%20the%20next%20cell%2C%20we%20***hide%20the%20code***%20that%20plots%20three%20functions%20together.%20To%20run%20the%20cell%2C%20click%20the%20blurred%20area%20of%20the%20cell%20to%20bring%20its%20contents%20back%20to%20the%20surface.%20To%20display%20its%20output%20(a%20plot%20with%20three%20functions)%2C%20delete%20the%20semi-comma%20%3Ckbd%3E%3B%3C%2Fkbd%3E%20that%20can%20be%20ound%20in%20the%20last%20line%2C%20and%20finally%20run%20the%20cell%20(%3Ckbd%3EShift%3C%2Fkbd%3E%20and%20%3Ckbd%3EEnter%3C%2Fkbd%3E%2C%20or%20click%20on%20the%20%3Ckbd%3E%E2%96%B6%EF%B8%8F%3C%2Fkbd%3E%20button).%20The%20plot%20will%20then%20be%20produced.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(go%2C%20np)%3A%0A%20%20%20%20%23%20Multiple%20traces%20with%20different%20styles%0A%20%20%20%20x2%20%3D%20np.linspace(0%2C%203*np.pi%2C%20100)%0A%0A%20%20%20%20fig4%20%3D%20go.Figure()%0A%20%20%20%20fig4.add_trace(go.Scatter(%0A%20%20%20%20%20%20%20%20x%3Dx2%2C%20y%3Dnp.cos(x2)%2C%20mode%3D'lines'%2C%0A%20%20%20%20%20%20%20%20line%3Ddict(width%3D2%2C%20color%3D'blue')%2C%0A%20%20%20%20%20%20%20%20name%3D'Shrek'%0A%20%20%20%20))%0A%20%20%20%20fig4.add_trace(go.Scatter(%0A%20%20%20%20%20%20%20%20x%3Dx2%2C%20y%3Dnp.sin(x2)%2C%20mode%3D'lines'%2C%0A%20%20%20%20%20%20%20%20line%3Ddict(dash%3D'dashdot'%2C%20color%3D'BlueViolet')%2C%0A%20%20%20%20%20%20%20%20name%3D'Fiona'%0A%20%20%20%20))%0A%20%20%20%20fig4.add_trace(go.Scatter(%0A%20%20%20%20%20%20%20%20x%3Dx2%2C%20y%3Dnp.cos(x2)**2%20-%201%2F2%2C%20mode%3D'markers%2Blines'%2C%0A%20%20%20%20%20%20%20%20marker%3Ddict(symbol%3D'circle-open'%2C%20size%3D6%2C%20color%3D'red')%2C%0A%20%20%20%20%20%20%20%20line%3Ddict(width%3D0.5)%2C%0A%20%20%20%20%20%20%20%20name%3D'Donkey'%0A%20%20%20%20))%0A%20%20%20%20fig4.update_layout(%0A%20%20%20%20%20%20%20%20height%3D450%2C%0A%20%20%20%20%20%20%20%20hovermode%3D'x'%2C%0A%20%20%20%20%20%20%20%20title_text%3D'My%20fancy%20plot%20with%20different%20lines%20%26%20marker%20styles'%2C%0A%20%20%20%20%20%20%20%20title_x%3D0.5%2C%0A%20%20%20%20%20%20%20%20xaxis_range%20%3D%20%5B-0.1%2C%209.5%5D%2C%0A%20%20%20%20%20%20%20%20margin%3Ddict(l%3D70%2C%20r%3D60%2C%20t%3D70%2C%20b%3D60)%0A%20%20%20%20)%0A%20%20%20%20fig4%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%22%22%22%0A%20%20%20%20---%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%205.%20Magic%20things%20we%20can%20do%20with%20Marimo%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%23%20Write%20normal%20text%20and%20sophisticated%20mathematics%0A%20%20%20%20Consider%20now%20an%20optimization%20problem%20where%20the%20constraints%20are%20defined%20in%20terms%20of%20inequalities.%20This%20can%20be%20solved%20by%20using%20the%20famous%20Karush-Kuhn%E2%80%93Tucker%20conditions%2C%20which%20require%20too%20much%20space%20to%20be%20explained%20here.%20An%20excellent%20place%20to%20look%20at%20is%20Chapter%206%20of%20the%20textbook%3A%20Rangarajan%20K.%20Sundaram%20(1996).%20*A%20First%20Course%20in%20Optimization%20Theory*%2C%20Cambridge%20University%20Press.%0A%0A%20%20%20%20%24%24%5Cmax%20%5Cquad%20x_%7B1%7D%2B2%20x_%7B2%7D%2B5%20x_%7B3%7D%24%24%0A%0A%20%20%20%20subject%20to%0A%0A%20%20%20%20%24%24%5Cbegin%7Baligned%7D%0A%20%20%20%20-x_%7B1%7D%2Bx_%7B2%7D%2B3%20x_%7B3%7D%20%26%20%5Cleq-5%20%5C%5C%0A%20%20%20%20x_%7B1%7D%2B3%20x_%7B2%7D-7%20x_%7B3%7D%20%26%20%5Cleq%2010%20%5C%5C%0A%20%20%20%200%20%5Cleq%20x_%7B1%7D%20%26%20%5Cleq%2010%20%5C%5C%0A%20%20%20%20x_%7B2%7D%20%26%20%5Cgeq%200%20%5C%5C%0A%20%20%20%20x_%7B3%7D%20%26%20%5Cgeq%200%0A%20%20%20%20%5Cend%7Baligned%7D%24%24%0A%0A%20%20%20%20And%20then%2C%20blah%20blah%20blah%20....%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%22%22%22%0A%20%20%20%20---%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%23%20Use%20Unicode%20symbols%20for%20writing%20text%20and%20doing%20computation%0A%0A%20%20%20%20Contary%20to%20Julia%2C%20in%20Python%2C%20we%20***cannot***%20use%20fancy%20unicode%20characters%20to%20do%20computation.%20I%20have%20a%20%F0%9F%98%BA%20that%20loves%20the%20%F0%9F%8C%9A%2C%20but%20not%20%F0%9F%8D%8D.%20In%20Julia%2C%20we%20can%20write%20simple%20text%20or%20do%20computations%20with%20these%20adorable%20objects.%20In%20Python%2C%20we%20can%20use%20them%20only%20as%20part%20of%20markdown%20text.%0A%0A%20%20%20%20To%20write%20special%20characters%20that%20are%20frequently%20used%20in%20Economics%20(like%20greek%20letters%3A%20%20%CE%B2%2C%20%CE%B1%2C%20for%20example)%20in%20Python%2C%20you%20have%20to%20copy-paste%20from%20character%20lists%20and%20such%20an%20exercise%20is%20not%20very%20efficient%3A%0A%20%20%20%20-%20Copy%2Bpaste%20unicode%20directly%20from%20a%20list%3A%20%CE%B2%2C%20%CE%B1%2C%20%CE%B8%20%2C%20%CF%86%0A%0A%20%20%20%20-%20Complete%20list%3A%20%CE%B1%20%CE%B2%20%CE%B3%20%CE%B4%20%CE%B5%20%CE%B6%20%CE%B7%20%CE%B8%20%CE%B9%20%CE%BA%20%CE%BB%20%CE%BC%20%CE%BD%20%CE%BE%20%CE%BF%20%CF%80%20%CF%81%20%CF%83%20%CF%84%20%CF%85%20%CF%86%20%CF%87%20%CF%88%20%CF%89%0A%20%20%20%20%CE%91%20%CE%92%20%CE%93%20%CE%94%20%CE%95%20%CE%96%20%CE%97%20%CE%98%20%CE%99%20%CE%9A%20%CE%9B%20%CE%9C%20%CE%9D%20%CE%9E%20%CE%9F%20%CE%A0%20%CE%A1%20%CE%A3%20%CE%A4%20%CE%A5%20%CE%A6%20%CE%A7%20%CE%A8%20%CE%A9%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20%CE%B2%20%3D%203%0A%20%20%20%20return%20(%CE%B2%2C)%0A%0A%0A%40app.cell%0Adef%20_(%CE%B2)%3A%0A%20%20%20%20%CE%B1%20%3D%2010%20*%20%CE%B2%0A%20%20%20%20return%20(%CE%B1%2C)%0A%0A%0A%40app.cell%0Adef%20_(%CE%B2)%3A%0A%20%20%20%20beta_squared%20%3D%20%CE%B2**2%0A%20%20%20%20return%20(beta_squared%2C)%0A%0A%0A%40app.cell%0Adef%20_(beta_squared%2C%20%CE%B1%2C%20%CE%B2)%3A%0A%0A%20%20%20%20%CE%B2%2C%20%CE%B1%2C%20beta_squared%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%22%22%22%0A%20%20%20%20---%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%23%20Play%20with%20sliders%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%F0%9F%91%89%20**Exercise%205**%0A%0A%20%20%20%20Move%20the%20two%20sliders%20above%20(one%20slide%20at%20a%20time)%2C%20and%20see%20what%20happens%20to%20the%20equilibrium%20in%20the%20plot%20above.%0A%0A%20%20%20%20**Answer%3A**%20The%20equilibrium%20will%20shift%20based%20on%20changes%20in%20aggregate%20demand%20(%CE%94%C4%80)%20and%20potential%20output%20(%CE%94Y%E1%B4%BE).%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20%23%20Supply%20and%20demand%20sliders%0A%20%20%20%20delta_A_slider%20%3D%20mo.ui.slider(-1.0%2C%201.0%2C%20value%3D0.0%2C%20step%3D0.01%2C%20show_value%3DTrue%2C%20label%3D%22%CE%94%C4%80%22)%0A%20%20%20%20delta_Yp_slider%20%3D%20mo.ui.slider(-1.0%2C%201.0%2C%20value%3D0.0%2C%20step%3D0.05%2C%20show_value%3DTrue%2C%20label%3D%22%CE%94Y%E1%B4%BE%22)%0A%0A%20%20%20%20mo.hstack(%5Bdelta_A_slider%2C%20delta_Yp_slider%5D%2Cjustify%3D%22center%22%2C%20gap%3D6)%0A%20%20%20%20return%20delta_A_slider%2C%20delta_Yp_slider%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(delta_A_slider%2C%20delta_Yp_slider%2C%20go%2C%20np)%3A%0A%20%20%20%20%23%20Supply%20and%20demand%20equilibrium%20plot%0A%20%20%20%20delta_A%20%3D%20delta_A_slider.value%0A%20%20%20%20delta_Yp%20%3D%20delta_Yp_slider.value%0A%0A%20%20%20%20%23%20Parameters%0A%20%20%20%20A_bar%20%3D%208.0%0A%20%20%20%20lambda_param%20%3D%200.5%0A%20%20%20%20m%20%3D%202.0%0A%20%20%20%20phi%20%3D%200.2%0A%20%20%20%20r_bar%20%3D%202.0%0A%20%20%20%20gamma%20%3D%202.8%0A%20%20%20%20Yp%20%3D%2014.8%0A%20%20%20%20pi_e%20%3D%202.0%0A%20%20%20%20rho%20%3D%200.0%0A%0A%20%20%20%20Y_range%20%3D%20np.arange(13.8%2C%2015.6%2C%200.01)%0A%0A%20%20%20%20%23%20AD%20curve%0A%20%20%20%20pi_d_max%20%3D%20(A_bar%20%2F%20(lambda_param%20*%20phi))%20-%20r_bar%20%2F%20lambda_param%0A%20%20%20%20pi_d%20%3D%20pi_d_max%20-%20(1%20%2F%20(m%20*%20phi%20*%20lambda_param))%20*%20Y_range%0A%0A%20%20%20%20%23%20AS%20curve%0A%20%20%20%20pi_s_min%20%3D%20pi_e%20-%20gamma%20*%20Yp%20%2B%20rho%0A%20%20%20%20pi_s%20%3D%20pi_s_min%20%2B%20gamma%20*%20Y_range%0A%0A%20%20%20%20%23%20Updated%20AD%20curve%20with%20delta_A%0A%20%20%20%20pi_d_max_new%20%3D%20((A_bar%20%2B%20delta_A)%20%2F%20(lambda_param%20*%20phi))%20-%20r_bar%20%2F%20lambda_param%0A%20%20%20%20pi_d_new%20%3D%20pi_d_max_new%20-%20(1%20%2F%20(m%20*%20phi%20*%20lambda_param))%20*%20Y_range%0A%0A%20%20%20%20fig_econ%20%3D%20go.Figure()%0A%0A%20%20%20%20%23%20Potential%20output%20line%0A%20%20%20%20fig_econ.add_trace(go.Scatter(%0A%20%20%20%20%20%20%20%20x%3D%5BYp%20%2B%20delta_Yp%2C%20Yp%20%2B%20delta_Yp%5D%2C%20y%3D%5B-5%2C%2010%5D%2C%0A%20%20%20%20%20%20%20%20mode%3D'lines'%2C%20line%3Ddict(width%3D4%2C%20color%3D'Orange')%2C%0A%20%20%20%20%20%20%20%20name%3D'Y%E1%B4%BE'%0A%20%20%20%20))%0A%0A%20%20%20%20%23%20Original%20AD%20and%20AS%20curves%0A%20%20%20%20fig_econ.add_trace(go.Scatter(x%3DY_range%2C%20y%3Dpi_d%2C%20mode%3D'lines'%2C%20%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20line%3Ddict(color%3D'Blue'%2C%20width%3D3)%2C%20name%3D'AD'))%0A%20%20%20%20fig_econ.add_trace(go.Scatter(x%3DY_range%2C%20y%3Dpi_s%2C%20mode%3D'lines'%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20line%3Ddict(color%3D'Red'%2C%20width%3D3)%2C%20name%3D'AS'))%0A%0A%20%20%20%20%23%20New%20AD%20curve%0A%20%20%20%20if%20delta_A%20!%3D%200%3A%0A%20%20%20%20%20%20%20%20fig_econ.add_trace(go.Scatter(x%3DY_range%2C%20y%3Dpi_d_new%2C%20mode%3D'lines'%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20line%3Ddict(color%3D'Magenta'%2C%20width%3D3)%2C%20name%3D'AD2'))%0A%0A%20%20%20%20%23%20Equilibrium%20point%0A%20%20%20%20fig_econ.add_trace(go.Scatter(%0A%20%20%20%20%20%20%20%20x%3D%5B14.8%5D%2C%20y%3D%5B2.0%5D%2C%20mode%3D'markers%2Btext'%2C%0A%20%20%20%20%20%20%20%20marker%3Ddict(size%3D12%2C%20color%3D'Blue')%2C%0A%20%20%20%20%20%20%20%20text%3D%5B'1'%5D%2C%20textposition%3D'top%20center'%2C%0A%20%20%20%20%20%20%20%20textfont%3Ddict(size%3D18%2C%20color%3D'black')%2C%0A%20%20%20%20%20%20%20%20name%3D'Eq1'%2C%20showlegend%3DFalse%0A%20%20%20%20))%0A%0A%20%20%20%20fig_econ.update_layout(%0A%20%20%20%20%20%20%20%20height%3D450%2C%0A%20%20%20%20%20%20%20%20title_text%3D'Initial%20long-term%20equilibrium'%2C%0A%20%20%20%20%20%20%20%20title_x%3D0.5%2C%0A%20%20%20%20%20%20%20%20hovermode%3D'x'%2C%0A%20%20%20%20%20%20%20%20xaxis%3Ddict(title%3D'GDP%20trillion%20dollars%20(Y)'%2C%20range%3D%5B14.2%2C%2015.4%5D)%2C%0A%20%20%20%20%20%20%20%20yaxis%3Ddict(title%3D'Rate%20of%20inflation%20(%CF%80)'%2C%20range%3D%5B-0.8%2C%205%5D)%2C%0A%20%20%20%20%20%20%20%20margin%3Ddict(l%3D70%2C%20r%3D60%2C%20t%3D70%2C%20b%3D60)%0A%20%20%20%20)%0A%0A%20%20%20%20fig_econ%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%2F%2F%2F%20hint%20%7C%20Answer%3A%20Exercise%205%0A%0A%20%20%20%20The%20equilibrium%20initially%20given%20by%20point%201%20will%20cahnge.%0A%20%20%20%20-%20%CE%94%C4%80%20will%20force%20the%20AD%20curve%20to%20shift%0A%20%20%20%20-%20%CE%94Y%E1%B4%BE%20will%20force%20the%20Y%E1%B4%BE%20curve%20to%20shift%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%F0%9F%91%89%20**Exercise%206**%0A%0A%20%20%20%20Move%20the%20two%20sliders%20above%20(one%20slide%20at%20a%20time)%2C%20and%20see%20what%20happens%20to%20the%20sinusoidal%20wave.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20%23%20Wave%20sliders%0A%20%20%20%20frequency_slider%20%3D%20mo.ui.slider(0.0%2C%203.0%2C%20value%3D1.0%2C%20step%3D0.1%2C%20show_value%3DTrue%2C%20label%3D%22frequency%22)%0A%20%20%20%20damping_slider%20%3D%20mo.ui.slider(-0.5%2C%200.8%2C%20value%3D0.0%2C%20step%3D0.01%2C%20show_value%3DTrue%2C%20label%3D%22damping%22)%0A%0A%20%20%20%20mo.hstack(%5Bfrequency_slider%2C%20damping_slider%5D%2C%20justify%3D%22center%22%2C%20gap%3D6)%0A%20%20%20%20return%20damping_slider%2C%20frequency_slider%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(damping_slider%2C%20frequency_slider%2C%20go%2C%20np)%3A%0A%20%20%20%20%23%20Damped%20sinusoidal%20wave%0A%20%20%20%20frequency%20%3D%20frequency_slider.value%0A%20%20%20%20damping%20%3D%20damping_slider.value%0A%0A%20%20%20%20tau%20%3D%20np.arange(1%2C%2020%2C%200.01)%0A%20%20%20%20wave%20%3D%20np.exp(-damping%20*%20tau)%20*%20np.sin(frequency%20*%20tau)%0A%0A%20%20%20%20fig_wave%20%3D%20go.Figure()%0A%20%20%20%20fig_wave.add_trace(go.Scatter(x%3Dtau%2C%20y%3Dwave%2C%20mode%3D'lines'))%0A%20%20%20%20fig_wave.update_layout(height%3D450%2C%20margin%3Ddict(l%3D70%2C%20r%3D60%2C%20t%3D70%2C%20b%3D60))%0A%20%20%20%20fig_wave%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%23%20Calculate%20an%20integral%0A%20%20%20%20%F0%9F%91%89%20**Exercise%207**%0A%0A%20%20%20%20We%20can%20estimate%20the%20integral%20of%20a%20function%20%24F%3A%5Ba%2Cb%5D%20%5Crightarrow%20%5Cmathbb%7BR%7D%24%20using%20the%20midpoint%20rule%20approximation.%20Let%20us%20interactively%20estimate%20%24%5Cint_0%5E1%20F(x)%20dx%24%20in%20the%20case%20of%3A%0A%0A%20%20%20%20%24%24F(x)%3D%20-%20x%5Csin(2%5Cpi%20x)%24%24%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20Nbins_slider%20%3D%20mo.ui.slider(1%2C%20500%2C%20value%3D20%2C%20step%3D1%2C%20show_value%3DTrue%2C%20label%3D%22Number%20of%20intervals%22)%0A%20%20%20%20Nbins_slider%0A%20%20%20%20return%20(Nbins_slider%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(Nbins_slider%2C%20go%2C%20np)%3A%0A%20%20%20%20%23%20Midpoint%20rule%20integral%20approximation%0A%20%20%20%20Nbins%20%3D%20Nbins_slider.value%0A%0A%20%20%20%20def%20F_func(x)%3A%0A%20%20%20%20%20%20%20%20return%20-x%20*%20np.sin(2%20*%20np.pi%20*%20x)%0A%0A%20%20%20%20centres%20%3D%20np.arange(1%2F(2*Nbins)%2C%201%2C%201%2FNbins)%0A%20%20%20%20midpointarea%20%3D%20round(sum(F_func(centres))%20%2F%20Nbins%2C%206)%0A%0A%20%20%20%20fig_integral%20%3D%20go.Figure()%0A%20%20%20%20fig_integral.add_trace(go.Bar(x%3Dcentres%2C%20y%3DF_func(centres)%2C%20name%3D'Area'))%0A%20%20%20%20fig_integral.add_trace(go.Scatter(x%3Dcentres%2C%20y%3DF_func(centres)%2C%20mode%3D'lines'%2C%20name%3D'F(x)'))%0A%20%20%20%20fig_integral.update_layout(%0A%20%20%20%20%20%20%20%20height%3D450%2C%0A%20%20%20%20%20%20%20%20title_text%3Df'Midpoint%20rule%20estimate%20with%20%7BNbins%7D%20intervals%20%3D%20%7Bmidpointarea%7D'%2C%0A%20%20%20%20%20%20%20%20margin%3Ddict(l%3D70%2C%20r%3D60%2C%20t%3D70%2C%20b%3D60)%0A%20%20%20%20)%0A%20%20%20%20fig_integral%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%22%22%22%0A%20%20%20%20---%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%23%20Playing%20with%20questions%20%26%20answers%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%F0%9F%91%89%F0%9F%91%89%20**Exercise%208**%0A%0A%20%20%20%20Table%201%20shows%20some%20important%20macroeconomic%20aggregates%2C%20measured%20in%20**real%20terms**%2C%20for%20the%20US%20economy%20in%202013.%20Answer%20questions%20**a)**%20and%20**b)**%20below.%0A%0A%20%20%20%20%7C%20Code%20%7C%20Headings%20%7C%20Billions%20of%20dollars%20%7C%0A%20%20%20%20%7C------%7C%3A----------%7C---------------------%7C%0A%20%20%20%20%7C%20cons%20%7C%20Private%20Consumption%20Expenditures%20%7C%2011400%20%7C%0A%20%20%20%20%7C%20inve%20%7C%20Investment%20in%20Equipment%20and%20Structures%20%7C%202600%20%7C%0A%20%20%20%20%7C%20stoc%20%7C%20Inventories%20%7C%2080%20%7C%0A%20%20%20%20%7C%20gove%20%7C%20Public%20Expenditures%20%7C%203120%20%7C%0A%20%20%20%20%7C%20expo%20%7C%20Exports%20%7C%202250%20%7C%0A%20%20%20%20%7C%20impo%20%7C%20Imports%20%7C%203000%20%7C%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20%23%20Values%20from%20Table%201%20passed%20into%20the%20notebook%0A%20%20%20%20cons%20%3D%2011400%0A%20%20%20%20inve%20%3D%202600%0A%20%20%20%20stoc%20%3D%2080%0A%20%20%20%20gove%20%3D%203120%0A%20%20%20%20expo%20%3D%202250%0A%20%20%20%20impo%20%3D%203000%0A%20%20%20%20return%20cons%2C%20expo%2C%20gove%2C%20impo%2C%20inve%2C%20stoc%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%F0%9F%91%89%20**a)**%20Using%20Table%201%2C%20calculate%20GDP%20by%20the%20expenditure%20method.%0A%0A%20%20%20%20%2F%2F%2F%20warning%20%7C%20Hint%0A%20%20%20%20According%20to%20the%20usual%20definition%20of%20GDP%20by%20the%20expenditure%20method%2C%20GDP%20is%20equal%20to%20the%20sum%20of%20private%20consumption%2C%20plus%20public%20expenditure%20on%20goods%20and%20services%2C%20plus%20investment%20and%20inventories%2C%20plus%20exports%20minus%20imports.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(cons%2C%20expo%2C%20gove%2C%20impo%2C%20inve%2C%20stoc)%3A%0A%20%20%20%20%23%20Calculate%20GDP%0A%20%20%20%20GDP%20%3D%20cons%20%2B%20inve%20%2B%20stoc%20%2B%20gove%20%2B%20expo%20-%20impo%0A%20%20%20%20GDP%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%2F%2F%2F%20hint%20%7C%20Answer%20(a)%0A%0A%20%20%20%20GDP%20%3D%2016450%20billion%20dollars%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%F0%9F%91%89%20**b)**%20In%20a%20market%20economy%2C%20such%20as%20the%20one%20we%20live%20in%2C%20do%20you%20have%20any%20suggestion%20about%20the%20main%20macroeconomic%20variables%20that%20explain%20the%20behavior%20of%20private%20investment%3F%0A%0A%20%20%20%20%2F%2F%2F%20hint%20%7C**Answer%20(b)%3A**%0A%0A%20%20%20%20We%20have%20not%20yet%20discussed%20the%20main%20determinants%20of%20private%20investment%20in%20our%20economies.%20As%20we%20will%20see%20later%20in%20this%20course%2C%20those%20determinants%20are%3A%20real%20interest%20rates%2C%20financial%20frictions%2C%20and%20autonomous%20investment%20decisions.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%F0%9F%91%89%20**Exercise%208A**%20%20%3Cbr%3E%0A%0A%20%20%20%20We%20can%20use%20Marimo%20to%20create%20multiple-choice%20questions%20with%20some%20pedagogic%20feedback.%20Try%20to%20answer%20the%20following%20question.%20How%20much%20did%20the%20US%20GDP%20change%20in%202023%2C%20given%20the%20following%20facts%3A%0A%20%20%20%20-%20First%20Republic%20Bank%20shareholders%20lost%202%20billion%20dollars%20on%20March%2016%20due%20to%20the%20bank's%20collapse.%0A%20%20%20%20-%20Microsoft%20decided%20to%20invest%2010%20billion%20dollars%20in%20the%20development%20of%20ChatGPT%20(OpenAI).%0A%20%20%20%20-%20Amazon%20bought%20100%25%20of%20the%20capital%20of%20the%20company%20One%20Medical%20on%20February%2022%2C%202023%20for%204%20billion%20dollars.%3Cbr%3E%0A%0A%20%20%20%20**a)**%20%24%E2%88%922%24%20billion%20%24%2B10%24%20billion%20%24%2B4%24%20billion.%3Cbr%3E%0A%20%20%20%20**b)**%20%24%2B4%24%20billion.%3Cbr%3E%0A%20%20%20%20**c)**%20%24%2B10%24%20billion%20%24%2B4%24%20billion.%3Cbr%3E%0A%20%20%20%20**d)**%20%24%2B10%24%20billion.%3Cbr%3E%0A%20%20%20%20**e)**%20None%20of%20the%20above.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(feedback_q10%2C%20mo%2C%20q10_shaded)%3A%0A%20%20%20%20mo.hstack(%5Bq10_shaded%2C%20feedback_q10%5D%2C%20justify%3D%22center%22%2C%20gap%3D6)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20%23%20Display%20the%20radio%20button%20with%20options%0A%20%20%20%20q10%20%3D%20mo.ui.radio(%0A%20%20%20%20%20%20%20%20options%3D%5B%22a%22%2C%20%22b%22%2C%20%22c%22%2C%20%22d%22%2C%20%22e%22%5D%2C%0A%20%20%20%20%20%20%20%20inline%3DTrue%2C%20%0A%20%20%20%20%20%20%20%20label%3D%22***Please%20select%20an%20answer***%20%F0%9F%91%89%20%24~~%24%22%0A%20%20%20%20)%0A%0A%20%20%20%20%23%20Marimo%20objects%20automatically%20convert%20to%20HTML%20when%20placed%20in%20an%20f-string%20inside%20mo.Html%0A%20%20%20%20q10_shaded%20%3D%20mo.Html(f%22%22%22%0A%20%20%20%20%20%20%20%20%3Cdiv%20style%3D%22position%3A%20relative%3B%20display%3A%20inline-block%3B%20padding%3A%2010px%3B%22%3E%0A%20%20%20%20%20%20%20%20%20%20%20%20%7Bq10%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20%3Cdiv%20style%3D%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20position%3A%20absolute%3B%20%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20top%3A%200%3B%20left%3A%200%3B%20%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20width%3A%20100%25%3B%20height%3A%20100%25%3B%20%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%2F*%20Use%20white%20(255%2C%20255%2C%20255)%20for%20dark%20mode%20*%2F%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20background%3A%20rgba(100%2C%20149%2C%20237%2C%200.35)%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20pointer-events%3A%20none%3B%20%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20border-radius%3A%2020px%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20z-index%3A%205%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%22%3E%3C%2Fdiv%3E%0A%20%20%20%20%20%20%20%20%3C%2Fdiv%3E%0A%20%20%20%20%22%22%22)%0A%0A%20%20%20%20q10_shaded%3B%0A%20%20%20%20return%20q10%2C%20q10_shaded%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo%2C%20q10)%3A%0A%20%20%20%20if%20q10.value%20is%20None%3A%0A%20%20%20%20%20%20%20%20feedback_q10%20%3D%20mo.md(%22%F0%9F%91%80%20*We%20are%20waiting%20for%20your%20choice.*%22)%0A%20%20%20%20elif%20q10.value%20%3D%3D%20%22d%22%3A%0A%20%20%20%20%20%20%20%20feedback_q10%20%3D%20mo.md(%22%F0%9F%8E%89%20**Correct!**%20Microsoft's%20investment%20in%20ChatGPT%20development%20counts%20as%20new%20investment%2C%20increasing%20GDP%20by%2010%20billion.%20The%20bank%20collapse%20is%20a%20mere%20financial%20loss%20(doesn't%20affect%20GDP%20directly)%2C%20and%20Amazon's%20acquisition%20is%20a%20transfer%20of%20existing%20assets%20(not%20new%20production).%22)%0A%20%20%20%20else%3A%0A%20%20%20%20%20%20%20%20feedback_q10%20%3D%20mo.md(%22%F0%9F%91%8E%20**Wrong%20answer.**%20Try%20again.%20**But%20it%20is%20better%20to%20study%20first!**%20%F0%9F%98%A1%22)%0A%0A%20%20%20%20feedback_q10%3B%0A%20%20%20%20return%20(feedback_q10%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%F0%9F%91%89%20**Exercise%208B%3A%20demand%20vs%20supply%20in%20a%20market%20economy**%0A%0A%20%20%20%20As%20you%20have%20studied%20in%20introductory%20microeconomics%2C%20price%20adjustments%20are%20the%20mechanism%20that%20equilibrates%20markets.%20The%20following%20figure%20illustrates%20the%20interaction%20between%20supply%20and%20demand%20in%20a%20market%20economy%20that%20leads%20to%20such%20adjustments.%0A%0A%20%20%20%20What%20kind%20of%20information%20can%20we%20get%20by%20looking%20at%20points%201%20and%201'%3F%20And%20what%20happens%20in%20the%20case%20of%20points%202%20and%202'%3F%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(go%2C%20np)%3A%0A%20%20%20%20%23%20Supply%20and%20demand%20plot%0A%20%20%20%20Q_market%20%3D%20np.arange(0.0%2C%2025.0%2C%200.05)%0A%20%20%20%20P_supply%20%3D%200.0%20%2B%200.75%20*%20Q_market%0A%20%20%20%20P_demand%20%3D%2018.0%20-%200.75%20*%20Q_market%0A%0A%20%20%20%20fig_market%20%3D%20go.Figure()%0A%0A%20%20%20%20fig_market.add_trace(go.Scatter(%0A%20%20%20%20%20%20%20%20x%3DQ_market%2C%20y%3DP_demand%2C%20mode%3D'lines'%2C%0A%20%20%20%20%20%20%20%20line%3Ddict(color%3D'maroon'%2C%20width%3D2.2)%2C%0A%20%20%20%20%20%20%20%20name%3D'Q%E1%B5%88%20(Demand)'%0A%20%20%20%20))%0A%0A%20%20%20%20fig_market.add_trace(go.Scatter(%0A%20%20%20%20%20%20%20%20x%3DQ_market%2C%20y%3DP_supply%2C%20mode%3D'lines'%2C%0A%20%20%20%20%20%20%20%20line%3Ddict(color%3D'Blue'%2C%20width%3D2.2)%2C%0A%20%20%20%20%20%20%20%20name%3D'Q%CB%A2%20(Supply)'%0A%20%20%20%20))%0A%0A%20%20%20%20%23%20Points%20at%20price%208.25%0A%20%20%20%20fig_market.add_trace(go.Scatter(%0A%20%20%20%20%20%20%20%20x%3D%5B11.0%2C%2013.0%5D%2C%20y%3D%5B8.25%2C%208.25%5D%2C%0A%20%20%20%20%20%20%20%20mode%3D'markers%2Btext'%2C%20marker%3Ddict(size%3D11%2C%20color%3D'purple')%2C%0A%20%20%20%20%20%20%20%20text%3D%5B'1'%2C%20%221'%22%5D%2C%20textposition%3D'top%20center'%2C%0A%20%20%20%20%20%20%20%20textfont%3Ddict(size%3D16%2C%20color%3D'black')%2C%0A%20%20%20%20%20%20%20%20showlegend%3DFalse%2C%20hoverinfo%3D'skip'%0A%20%20%20%20))%0A%0A%20%20%20%20%23%20Points%20at%20price%209.75%0A%20%20%20%20fig_market.add_trace(go.Scatter(%0A%20%20%20%20%20%20%20%20x%3D%5B11.0%2C%2013.0%5D%2C%20y%3D%5B9.75%2C%209.75%5D%2C%0A%20%20%20%20%20%20%20%20mode%3D'markers%2Btext'%2C%20marker%3Ddict(size%3D11%2C%20color%3D'darkorange')%2C%0A%20%20%20%20%20%20%20%20text%3D%5B'2'%2C%20%222'%22%5D%2C%20textposition%3D'top%20center'%2C%0A%20%20%20%20%20%20%20%20textfont%3Ddict(size%3D16%2C%20color%3D'black')%2C%0A%20%20%20%20%20%20%20%20showlegend%3DFalse%2C%20hoverinfo%3D'skip'%0A%20%20%20%20))%0A%0A%20%20%20%20fig_market.update_layout(%0A%20%20%20%20%20%20%20%20height%3D450%2C%0A%20%20%20%20%20%20%20%20title_text%3D'Demand%20(Q%E1%B5%88)%20versus%20supply%20(Q%CB%A2)'%2C%0A%20%20%20%20%20%20%20%20title_x%3D0.5%2C%0A%20%20%20%20%20%20%20%20hovermode%3D'y%20unified'%2C%0A%20%20%20%20%20%20%20%20xaxis%3Ddict(title%3D'Quantity'%2C%20range%3D%5B9.0%2C%2015.0%5D)%2C%0A%20%20%20%20%20%20%20%20yaxis%3Ddict(title%3D'Price'%2C%20range%3D%5B6.5%2C%2011.5%5D)%2C%0A%20%20%20%20%20%20%20%20margin%3Ddict(l%3D70%2C%20r%3D60%2C%20t%3D70%2C%20b%3D60)%0A%20%20%20%20)%0A%0A%20%20%20%20fig_market%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%2F%2F%2F%20hint%20%7CAnswer%3A%20Exercise%208B%0A%0A%20%20%20%20Points%201%20and%201'%20tell%20us%20that%20for%20the%20price%20level%20of%208.25%2C%20there%20is%20excess%20demand%20(quantity%20demanded%20exceeds%20quantity%20supplied).%0A%0A%20%20%20%20Points%202%20and%202'%20tell%20us%20that%20for%20the%20price%20level%20of%209.75%2C%20there%20is%20excess%20supply%20(quantity%20supplied%20exceeds%20quantity%20demanded).%0A%0A%20%20%20%20The%20price%20will%20be%20stable%20when%20there%20is%20equilibrium%20(where%20supply%20equals%20demand).%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%22%22%22%0A%20%20%20%20---%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%206.%20Downloading%20and%20plotting%20data%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20To%20download%20and%20work%20with%20data%20files%2C%20we%20use%20the%20package%20named%20as%20%60pandas%60.%20A%20CSV%20file%20is%20the%20most%20used%20format%20to%20deal%20with%20data%20and%20it%20means%20%22comma%20separated%20values%22.%20To%20download%20the%20data%20file%20attached%20to%20this%20notebook%20%E2%80%93%20its%20name%20is%20%3Ckbd%3EECB%20Data%20Inflation.csv%3C%2Fkbd%3E%20%E2%80%93%20we%20should%20do%20as%20exemplified%20below.%20This%20data%20file%20contains%20the%20inflation%20rate%20for%20the%20EuroZone%20as%20a%20whole%20and%20four%20individual%20countries.%20This%20data%20was%20obtained%20from%20here.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(pd%2C%20preview)%3A%0A%20%20%20%20inflation%20%3D%20pd.read_csv(%22ECB%20Data%20Inflation.csv%22)%0A%20%20%20%20preview(inflation)%0A%20%20%20%20return%20(inflation%2C)%0A%0A%0A%40app.cell%0Adef%20_(inflation)%3A%0A%20%20%20%20%23%20Summary%20statistics%0A%20%20%20%20inflation.describe()%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(inflation%2C%20px)%3A%0A%20%20%20%20%23%20Plot%20single%20column%0A%20%20%20%20fig5%20%3D%20px.line(x%3Dinflation.Months%2C%20y%3D%20inflation.Portugal%2C%20%20title%20%3D%20%22Inflation%20in%20Portugal%22)%0A%20%20%20%20fig5.update_layout(height%3D500%2C%20%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20xaxis_title%20%3D%20%22Months%22%2C%20yaxis_title%20%3D%20%22Percentage%20points%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20margin%3Ddict(l%3D60%2C%20r%3D60%2C%20t%3D70%2C%20b%3D60))%0A%20%20%20%20fig5%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20To%20plot%20more%20than%20one%20column%2C%20we%20can%20create%20a%20vector%20%5B...%5D%20to%20include%20as%20many%20columns%20has%20we%20wish.%20In%20the%20case%20below%20we%20plot%20the%20columns%20associated%20with%20Germany%20and%20Portugal.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(inflation%2C%20px)%3A%0A%20%20%20%20fig12%20%3D%20px.line(x%3Dinflation.Months%2C%20y%3D%5Binflation.Portugal%20%2C%20inflation.Germany%5D%2C%20title%3D%22Inflation%20in%20Germany%20and%20Portugal%22%2C%20color_discrete_sequence%3D%5B%22%231919c9%22%2C%20%22maroon%22%5D)%20%231919c9%20%230248ff%0A%0A%20%20%20%20fig12.update_traces(mode%3D%22lines%22%2C%20hovertemplate%3DNone)%0A%0A%20%20%20%20fig12.update_layout(height%20%3D%20500%2C%20hovermode%3D%22x%22%2C%20xaxis_title%3D%22Months%22%2C%20yaxis_title%3D%22Percentage%20points%22%2C%20title_x%3D0.5%2C%20margin%3Ddict(l%3D70%2C%20r%3D70%2C%20t%3D70%2C%20b%3D60)%2C%20legend_title%3DNone)%0A%0A%20%20%20%20fig12.update_traces(%7B'name'%3A%20'Portugal'%7D%2C%20selector%3D%7B'name'%3A%20'wide_variable_0'%7D)%0A%20%20%20%20fig12.update_traces(%7B'name'%3A%20'Germany'%7D%2C%20selector%3D%7B'name'%3A%20'wide_variable_1'%7D)%0A%20%20%20%20fig12%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20The%20previous%20plot%20was%20made%20with%20Plotly%20Express%20%3Ckbd%3Epx%3C%2Fkbd%3E%2C%20which%20is%20the%20quickest%20way%20to%20perform%20plotting%20tasks.%20There%20is%20an%20alternative%20way%20of%20plotting%20the%20previous%20figure%20using%20the%20Plotly%20Graph%20Objects%20%3Ckbd%3Ego%3C%2Fkbd%3E.%20This%20new%20process%20provides%20more%20functionality%20for%20plotting%2C%20but%20it%20usually%20takes%20longer%20to%20write%20the%20code%20to%20produce%20the%20plots.%20The%20following%20plot%20was%20done%20using%20the%20%60go%60%20wrapper%20instead%20of%20%60px%60.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(go%2C%20inflation)%3A%0A%20%20%20%20%23%20Plot%20multiple%20columns%0A%20%20%20%20fig6%20%3D%20go.Figure()%0A%20%20%20%20fig6.add_trace(go.Scatter(%0A%20%20%20%20%20%20%20%20x%3Dinflation.Months%2C%0A%20%20%20%20%20%20%20%20y%3Dinflation.Germany%2C%0A%20%20%20%20%20%20%20%20mode%3D'lines'%2C%0A%20%20%20%20%20%20%20%20name%3D'Germany'%0A%20%20%20%20))%0A%20%20%20%20fig6.add_trace(go.Scatter(%0A%20%20%20%20%20%20%20%20x%3Dinflation.Months%2C%0A%20%20%20%20%20%20%20%20y%3Dinflation.Portugal%2C%0A%20%20%20%20%20%20%20%20mode%3D'lines'%2C%0A%20%20%20%20%20%20%20%20name%3D'Portugal'%0A%20%20%20%20))%0A%20%20%20%20fig6.update_layout(%0A%20%20%20%20%20%20%20%20height%3D500%2C%0A%20%20%20%20%20%20%20%20title_text%3D'Inflation%20in%20Germany%20and%20Portugal'%2C%0A%20%20%20%20%20%20%20%20title_x%3D0.5%2C%0A%20%20%20%20%20%20%20%20hovermode%3D'x'%2C%0A%20%20%20%20%20%20%20%20yaxis_title%3D'Percentage%20points'%2C%0A%20%20%20%20%20%20%20%20xaxis_title%3D'Monthly%20observations%20coco'%2C%0A%20%20%20%20%20%20%20%20margin%3Ddict(l%3D70%2C%20r%3D60%2C%20t%3D70%2C%20b%3D60)%0A%20%20%20%20)%0A%20%20%20%20fig6%0A%20%20%20%20return%20(fig6%2C)%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%F0%9F%91%89%20**Exercise%209**%0A%0A%20%20%20%20We%20can%20also%20save%20one%20plot%20as%20a%20%22png%22%20file%2C%20a%20%22pdf%22%20file%2C%20or%20an%20%22svg%22%20file%20(among%20many%20other%20formats).%20These%20files%20can%20be%20inserted%20later%20into%20another%20document%20(like%20a%20PowerPoint%20or%20a%20Word%20file).%20Their%20graphical%20quality%20will%20be%20much%20higher%20than%20by%20using%20the%20archaic%20%22screen-capture%22%20functionality.%20In%20the%20next%20cell%2C%20save%20%22fig6%22%20as%20an%20svg%2C%20a%20pdf%2C%20and%20a%20png%20file%20by%20copying%20and%20running%20the%20code%20%3Ckbd%3Efig6.write_image(%22inflation_plot.svg%22)%3C%2Fkbd%3E.%20They%20will%20be%20automatically%20saved%20in%20the%20same%20folder%20where%20this%20notebook%20is%20located.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(fig6)%3A%0A%20%20%20%20fig6.write_image(%22inflation_plot.svg%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(fig6)%3A%0A%20%20%20%20fig6.write_image(%22inflation_plot.pdf%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(fig6)%3A%0A%20%20%20%20fig6.write_image(%22inflation_plot.png%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(go%2C%20inflation)%3A%0A%20%20%20%20fig7%20%3D%20go.Figure()%0A%0A%20%20%20%20%20%20%20%20%23%20Add%20each%20country%20trace%20individually%0A%20%20%20%20fig7.add_trace(go.Scatter(%0A%20%20%20%20%20%20%20%20%20%20%20%20x%3Dinflation.Months%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20y%3Dinflation.EuroArea%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20mode%3D'markers%2Blines'%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20marker%3Ddict(size%3D4%2C%20color%3D'blue')%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20line%3Ddict(width%3D0.3%2C%20color%3D'blue')%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20name%3D'EuroArea'%0A%20%20%20%20%20%20%20%20))%0A%0A%20%20%20%20fig7.add_trace(go.Scatter(%0A%20%20%20%20%20%20%20%20%20%20%20%20x%3Dinflation.Months%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20y%3Dinflation.Portugal%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20mode%3D'markers%2Blines'%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20marker%3Ddict(size%3D4%2C%20color%3D'maroon')%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20line%3Ddict(width%3D0.3%2C%20color%3D'maroon')%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20name%3D'Portugal'%0A%20%20%20%20%20%20%20%20))%0A%0A%20%20%20%20fig7.add_trace(go.Scatter(%0A%20%20%20%20%20%20%20%20%20%20%20%20x%3Dinflation.Months%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20y%3Dinflation.Germany%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20mode%3D'markers%2Blines'%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20marker%3Ddict(size%3D4%2C%20color%3D'cyan')%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20line%3Ddict(width%3D0.3%2C%20color%3D'cyan')%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20name%3D'Germany'%0A%20%20%20%20%20%20%20%20))%0A%0A%20%20%20%20fig7.add_trace(go.Scatter(%0A%20%20%20%20%20%20%20%20%20%20%20%20x%3Dinflation.Months%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20y%3Dinflation.Spain%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20mode%3D'markers%2Blines'%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20marker%3Ddict(size%3D4%2C%20color%3D'darkorange')%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20line%3Ddict(width%3D0.3%2C%20color%3D'darkorange')%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20name%3D'Spain'%0A%20%20%20%20%20%20%20%20))%0A%0A%20%20%20%20fig7.add_trace(go.Scatter(%0A%20%20%20%20%20%20%20%20%20%20%20%20x%3Dinflation.Months%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20y%3Dinflation.France%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20mode%3D'markers%2Blines'%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20marker%3Ddict(size%3D4%2C%20color%3D'purple')%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20line%3Ddict(width%3D0.3%2C%20color%3D'purple')%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20name%3D'France'%0A%20%20%20%20%20%20%20%20))%0A%0A%20%20%20%20fig7.update_layout(%0A%20%20%20%20%20%20%20%20%20%20%20%20height%3D500%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20title_text%3D'Inflation%20in%20the%20EuroArea%20and%20four%20European%20countries'%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20title_x%3D0.5%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20hovermode%3D'x'%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20xaxis_range%3D%5B%221996-10-1%22%2C%20%222024-06-1%22%5D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20yaxis_title%3D'Percentage%20points'%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20margin%3Ddict(l%3D70%2C%20r%3D60%2C%20t%3D70%2C%20b%3D60)%0A%20%20%20%20%20%20%20%20)%0A%0A%20%20%20%20fig7%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20Notice%20that%20there%20is%20a%20shorter%20way%20to%20produce%20the%20same%20plot%20as%20above%3A%20use%20a%20%3Ckbd%3Efor%20loop%3C%2Fkbd%3E%20for%20countries%20and%20colors.%20See%20the%20following%20figure.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(go%2C%20inflation)%3A%0A%20%20%20%20%23%20Comprehensive%20inflation%20plot%0A%0A%20%20%20%20fig7a%20%3D%20go.Figure()%0A%0A%20%20%20%20colors7a%20%3D%20%5B%22blue%22%2C%20%22maroon%22%2C%20%22cyan%22%2C%20%22darkorange%22%2C%20%22teal%22%5D%0A%20%20%20%20countries7a%20%3D%20%5B'EuroArea'%2C%20'Portugal'%2C%20'Germany'%2C%20'Spain'%2C%20'France'%5D%0A%0A%20%20%20%20for%20i%2C%20country%20in%20enumerate(countries7a)%3A%0A%20%20%20%20%20%20%20%20fig7a.add_trace(go.Scatter(%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20x%3Dinflation.Months%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20y%3Dinflation%5Bcountry%5D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20mode%3D'markers%2Blines'%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20marker%3Ddict(size%3D4%2C%20color%3Dcolors7a%5Bi%5D)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20line%3Ddict(width%3D0.3%2C%20color%3Dcolors7a%5Bi%5D)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20name%3Dcountry%0A%20%20%20%20%20%20%20%20%20%20%20%20))%0A%0A%20%20%20%20fig7a.update_layout(%0A%20%20%20%20%20%20%20%20%20%20%20%20height%3D500%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20title_text%3D'Inflation%20in%20the%20EuroZone%20and%20Portugal'%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20title_x%3D0.5%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20hovermode%3D'x'%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20xaxis_range%3D%5B%221996-10-1%22%2C%20%222024-06-1%22%5D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20yaxis_title%3D'Percentage%20points'%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20margin%3Ddict(l%3D70%2C%20r%3D60%2C%20t%3D70%2C%20b%3D60)%0A%20%20%20%20%20%20%20%20)%0A%0A%20%20%20%20fig7a%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%F0%9F%91%89%20**Exercise%209A**%0A%0A%20%20%20%20Create%20a%20simple%20plot%20of%20the%20following%20variable%3A%20%3Ckbd%3Einflation.EuroArea%20%20-%20%202%3C%2Fkbd%3E.%20That%20is%2C%20EuroArea%20inflation%20minus%202%25%20inflation%20(2.5%25%20inflation%20is%20the%20the%20inflation%20rate%20the%20European%20Central%20Bank%20(ECB)%20is%20asked%20to%20achieve).%20To%20produce%20that%2C%20apply%20the%20following%20code%20(see%20the%20plot%20below%20for%20more%20details)%3A%0A%0A%20%20%20%20%3Ckbd%3Efig8%20%3D%20px.bar(x%3Dinflation.Months%2C%20y%3D(inflation.EuroArea%20-%202)%3C%2Fkbd%3E%0A%0A%20%20%20%20where%20%22px.bar%22%20means%20that%20we%20want%20the%20data%20to%20be%20plotted%20as%20a%20bar%2C%20not%20as%20a%20line.%20The%20level%20of%20inflation%20the%20European%20Central%20Bank%20wants%20to%20see%20in%20the%20Euro%20Zone%20is%202%25.%20Check%20whether%20the%20wishes%20of%20the%20ECB%20have%20been%20accomplished%20in%20the%20EU.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(inflation%2C%20px)%3A%0A%20%20%20%20%23%20Bar%20plot%20of%20inflation%20deviation%20from%20target%0A%20%20%20%20fig8%20%3D%20px.bar(x%3Dinflation.Months%2C%20y%3D(inflation.EuroArea%20-%202)%2C%20color_discrete_sequence%3D%5B'darkred'%5D%20)%0A%20%20%20%20fig8.update_layout(height%3D450%2C%20title_text%3D'EuroArea%20Inflation%20Deviation%20from%202%25%20Target'%2C%20hovermode%20%3D%20%22x%22)%0A%20%20%20%20fig8%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%2F%2F%2F%20hint%20%7C%20Answer%3A%20Exercise%209A%0A%20%20%20%20Between%202000%20and%20mid-2007%2C%20the%20European%20central%20Bank%20(ECB)%20was%20very%20successful%20in%20maintaining%20inflation%20very%20close%20to%20the%20desired%20level%3A%202%25.%20Since%20then%2C%20the%20ECB%20has%20shown%20tremendous%20difficulty%20maintaining%20inflation%20close%20to%20its%20desired%20level%2C%20and%20this%20is%20not%20good%20given%20the%20job%20that%20is%20expected%20from%20the%20ECB.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%207.%20Using%20linear%20algebra%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20**Warning%3A**%20In%20computation%2C%20there%20is%20a%20crucial%20difference%20between%20a%20%3Ckbd%3E%2C%3C%2Fkbd%3E%20and%20a%20%3Ckbd%3E.%3C%2Fkbd%3E%20.%20In%20Python%2C%20we%20use%20%3Ckbd%3E.%3C%2Fkbd%3E%20for%20decimal%20numbers%3A%201%2F2%20%3D%200.5%2C%20NOT%201%2F2%20%3D%200%2C5.%20If%20you%20mistakenly%20use%20a%20%3Ckbd%3E%2C%3C%2Fkbd%3E%20to%20express%20decimal%20units%2C%20you%20will%20create%20a%20problem%20your%20computer%20does%20not%20know%20how%20to%20solve.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(np)%3A%0A%20%20%20%20%23%20Matrix%20operations%0A%20%20%20%20A%20%3D%20np.array(%5B%5B1%2C%202%2C%203%5D%2C%20%5B4%2C%201%2C%206%5D%2C%20%5B7%2C%208%2C%201%5D%5D)%0A%20%20%20%20A%0A%20%20%20%20return%20(A%2C)%0A%0A%0A%40app.cell%0Adef%20_(A%2C%20np)%3A%0A%20%20%20%20%23%20Matrix%20inverse%0A%20%20%20%20A_inv%20%3D%20np.linalg.inv(A)%0A%20%20%20%20A_inv%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(A)%3A%0A%20%20%20%20%23%20Matrix%20transpose%0A%20%20%20%20A_transpose%20%3D%20A.T%0A%20%20%20%20A_transpose%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(A%2C%20np)%3A%0A%20%20%20%20%23%20Matrix%20determinant%0A%20%20%20%20A_det%20%3D%20np.linalg.det(A)%0A%20%20%20%20A_det%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(A)%3A%0A%20%20%20%20%23%20Matrix%20power%0A%20%20%20%20A_squared%20%3D%20A%20%40%20A%20%20%23%20or%20np.linalg.matrix_power(A%2C%202)%0A%20%20%20%20A_squared%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(np)%3A%0A%20%20%20%20%23%20Random%20matrix%0A%20%20%20%20Zak%20%3D%20np.random.randn(3%2C%203)%0A%20%20%20%20Zak%0A%20%20%20%20return%20(Zak%2C)%0A%0A%0A%40app.cell%0Adef%20_(A%2C%20Zak)%3A%0A%20%20%20%20%23%20Matrix%20multiplication%0A%20%20%20%20aple%20%3D%20A%20%40%20Zak%0A%20%20%20%20aple%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(np)%3A%0A%20%20%20%20%23%20Random%20integer%20matrix%0A%20%20%20%20F%20%3D%20np.random.randint(1%2C%2011%2C%20size%3D(5%2C%205))%0A%20%20%20%20F%0A%20%20%20%20return%20(F%2C)%0A%0A%0A%40app.cell%0Adef%20_(F)%3A%0A%20%20%20%20%23%20Matrix%20indexing%20(Python%20uses%200-based%20indexing)%0A%20%20%20%20F%5B0%2C%202%5D%20%20%23%20First%20row%2C%20third%20column%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%F0%9F%91%89%20**Exercise%2010**%0A%0A%20%20%20%20Let%20us%20create%20a%20matrix%20of%20dimension%20(100%C3%97100)%2C%20with%20all%20its%20elements%20as%20randomly%20generated%20numbers.%20Give%20this%20matrix%20the%20name%20Shrek%20and%20calculate%20its%20inverse.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(np)%3A%0A%20%20%20%20%23%20Large%20random%20matrix%0A%20%20%20%20Shrek%20%3D%20np.random.randn(100%2C%20100)%0A%20%20%20%20Shrek%0A%20%20%20%20return%20(Shrek%2C)%0A%0A%0A%40app.cell%0Adef%20_(Shrek%2C%20np)%3A%0A%20%20%20%20%23%20Inverse%20of%20large%20matrix%0A%20%20%20%20Shrek_inv%20%3D%20np.linalg.inv(Shrek)%0A%20%20%20%20Shrek_inv%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%2F%2F%2F%20hint%20%7C%20Answer%3A%20Exercise%2010%0A%0A%20%20%20%20The%20time%20it%20takes%20to%20compute%20the%20inverse%20of%20Shrek%20(a%20100%C3%97100%20matrix)%20is%20very%20fast%20with%20NumPy%2C%20typically%20under%20a%20millisecond%20on%20modern%20hardware.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%22%22%22%0A%20%20%20%20---%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%208.%20Solving%20a%20complicated%20model%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%F0%9F%91%89%20**Exercise%2011**%0A%0A%20%20%20%20Consider%20the%20following%20prototype%20of%20a%20macroeconomic%20model%3A%0A%0A%20%20%20%20%24%24%5Cbegin%7Baligned%7D%0A%20%20%20%20%26%20y_%7B1%7D%20%3D%20a%20%2B%200.5%20y_%7B2%7D%20-%202.5%20y_%7B3%7D%20%5C%5C%0A%20%20%20%20%26%20y_%7B2%7D%20%3D%20-2%20y_%7B1%7D%20%2B%205%20y_%7B3%7D%20%2B%20b%20%5C%5C%0A%20%20%20%20%26%20y_%7B3%7D%20%3D%2010%20y_%7B1%7D%20%2B%202%20c%20%5C%5C%0A%20%20%20%20%26%20a%20%3D%2010%20%5C%2C%20%2C%20%5C%2C%20b%3D2%20%5C%2C%20%2C%20%5C%2C%20c%3D5%0A%20%20%20%20%5Cend%7Baligned%7D%24%24%0A%0A%20%20%20%20We%20can%20solve%20this%20system%20using%20the%20%3Ckbd%3Efsolve%3C%2Fkbd%3E%20function%20from%20the%20%60scipy%60%20library%20in%20Python.%20The%20first%20thing%20we%20should%20do%20is%20to%20pass%20the%20values%20of%20the%20variables%20with%20known%20values%20to%20the%20notebook%3A%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20%23%20Model%20parameters%0A%20%20%20%20a%20%3D%2010%0A%20%20%20%20b%20%3D%202%0A%20%20%20%20c%20%3D%205%0A%20%20%20%20p%20%3D%20%5Ba%20%2C%20b%20%2C%20c%5D%20%0A%20%20%20%20return%20(p%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%2F%2F%2F%20tip%20%7C%20Steps%20to%20solve%20this%20exercise%0A%20%20%20%20First%2C%20we%20rewrite%20the%20system%20as%20a%20homogeneous%20system%20(zeros%20on%20the%20left-hand%20side)%3A%0A%0A%20%20%20%20%24%24%5Cbegin%7Baligned%7D%0A%20%20%20%20%260%20%3D%20a%20%2B%200.5%20y_2%20-%202.5%20y_3%20-%20y_1%20%5C%5C%0A%20%20%20%20%260%20%3D%20-2%20y_1%20%2B%205%20y_3%20%2B%20b%20-%20y_2%20%5C%5C%0A%20%20%20%20%260%20%3D%2010%20y_1%20%2B%202c%20-%20y_3%0A%20%20%20%20%5Cend%7Baligned%7D%24%24%0A%0A%20%20%20%20Then%20we%20have%20to%20write%20down%20our%20problem%20according%20to%20the%20syntax%20of%20%60scipy.optimize%60%20(**see%20the%20image%20below%20for%20a%20graphical%20detailed%20description**)%0A%20%20%20%20-%20The%20keyword%20%3Ckbd%3Edef%3C%2Fkbd%3E%20tells%20the%20computer%20that%20you%20are%20going%20to%20define%20your%20problem%20with%20a%20set%20of%20elements%20that%20will%20come%20next%0A%20%20%20%20-%20Give%20a%20name%20to%20your%20problem%3A%20let%20us%20name%20it%20as%20%3Ckbd%3Epumbaa%3C%2Fkbd%3E%0A%20%20%20%20-%20Define%20the%20variables%20in%20our%20problem%3A%20%3Ckbd%3Epumbaa(v%2Cp)%3C%2Fkbd%3E%0A%20%20%20%20%20%20%20%20-%20%20%3Ckbd%3Ev%3C%2Fkbd%3E%20represents%20the%20set%20of%20**endogenous**%20variables%20(the%20letter%20used%20here%20%60v%60%20is%20arbitrary)%0A%20%20%20%20%20%20%20%20-%20%20%3Ckbd%3Ep%3C%2Fkbd%3E%20represents%20the%20set%20of%20**exogenous**%20variables%20(the%20letter%20%60z%60%20used%20here%20is%20arbitrary)%0A%20%20%20%20%20%20%20%20-%20%20%3Ckbd%3Ey1%20%2C%20y2%20%2C%20y3%20%3D%20v%3C%2Fkbd%3E%20is%20the%20(unpacked)%20set%20of%20endogenous%20variables%20in%20the%20current%20problem%20(the%20order%20is%20arbitrary)%0A%20%20%20%20%20%20%20%20-%20%20%20%3Ckbd%3Ea%20%2C%20b%20%2C%20c%20%3D%20p%3C%2Fkbd%3E%20is%20the%20(unpacked)%20set%20of%20exogenous%20variables%20in%20the%20current%20problem%20(the%20order%20is%20arbitrary)%0A%20%20%20%20-%20Define%20the%20equations%20in%20your%20problem%3A%0A%0A%20%20%20%20%24%24%5Cbegin%7Baligned%7D%0A%20%20%20%20E%20%3D%20%26%20%5C%20%5B%20%5C%20a%20%2B%200.5%20y_2%20-%202.5%20y_3%20-%20y_1%20%5C%20%2C%20%5C%5C%0A%20%20%20%20%26%20%5C%20%5C%20%5C%202%20y_1%20%2B%205%20y_3%20%2B%20b%20-%20y_2%20%5C%20%2C%20%5C%5C%0A%20%20%20%20%26%20%5C%20%5C%20%5C%2010%20y_1%20%2B%202c%20-%20y_3%20%5C%20%5D%0A%20%20%20%20%5Cend%7Baligned%7D%24%24%0A%0A%20%20%20%20Finally%2C%20we%20should%20compute%20the%20numerical%20solution%20to%20our%20problem%20according%20to%20the%20syntax%20of%20%60scipy.optimize%60%20(see%20the%20image%20below%20for%20details%20about%20this%20last%20step).%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(fsolve%2C%20p)%3A%0A%20%20%20%20%23%20Define%20our%20proble%3A%20equations%20(E)%2C%20variables%20(v)%2C%20and%20parameters%20(p)%0A%20%20%20%20def%20pumbaa(v%2C%20p)%3A%0A%20%20%20%20%20%20%20%20y1%2C%20y2%2C%20y3%20%3D%20v%0A%20%20%20%20%20%20%20%20a%2C%20b%20%2C%20c%20%3D%20p%20%0A%0A%20%20%20%20%20%20%20%20E%20%3D%20%5B%20a%20%2B%200.5*y2%20-%202.5*y3%20-%20y1%20%2C%20%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20-%202*y1%20%2B%205*y3%20%2B%20b%20-%20y2%20%2C%20%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%2010*y1%20%2B%202*c%20-y3%20%5D%0A%0A%20%20%20%20%20%20%20%20return%20E%0A%0A%20%20%20%20solution_pumbaa%20%3D%20fsolve(%20pumbaa%2C%20%5B1.0%2C%201.0%2C%201.0%5D%20%2C%20args%3D(p)%20)%0A%20%20%20%20solution_pumbaa%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%3Cdiv%20style%3D%22display%3A%20flex%3B%20justify-content%3A%20left%3B%20align-items%3A%20left%3B%22%3E%0A%20%20%20%20%20%20%20%20%3Cimg%0A%20%20%20%20%09%09src%3D%22http%3A%2F%2Fmodernmacro.org%2Fresources%2FVivaldo%2Ffigures%2FMarimo%2Ffsolve_pumbaa.svg%22%0A%20%20%20%20%09alt%3D%22Centered%20Image%22%20style%3D%22width%3A%2080%25%3B%20height%3A%20auto%3B%22%3E%0A%20%20%20%20%3C%2Fdiv%3E%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%2F%2F%2F%20hint%20%7C%20Answer%3AExercise%2011%0A%0A%20%20%20%20The%20solution%20is%20given%20by%3A%20%20y1%20%3D%205.5%20%2C%20y2%20%3D%20316%20%2C%20y3%20%3D%2065%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%22%22%22%0A%20%20%20%20---%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20Summary%0A%0A%20%20%20%20In%20this%20notebook%2C%20we%20covered%3A%0A%0A%20%20%20%201.%20Basic%20Marimo%20notebook%20concepts%20and%20reactive%20programming%0A%20%20%20%202.%20Markdown%20formatting%20and%20mathematical%20expressions%0A%20%20%20%203.%20Arithmetic%20operations%20and%20variable%20assignments%0A%20%20%20%204.%20Interactive%20plotting%20with%20Plotly%0A%20%20%20%205.%20Using%20sliders%20and%20interactive%20widgets%0A%20%20%20%206.%20Working%20with%20data%20using%20pandas%0A%20%20%20%207.%20Linear%20algebra%20with%20NumPy%0A%20%20%20%208.%20Solving%20systems%20of%20equations%20with%20scipy%0A%0A%20%20%20%20Marimo%20notebooks%20are%20reactive%2C%20meaning%20cells%20automatically%20re-run%20when%20their%20dependencies%20change.%20This%20ensures%20your%20notebook%20is%20always%20in%20a%20consistent%20state!%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20Auxiliary%20cells%20(please%20do%20not%20change%20them)%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%23%20Functions%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(pd)%3A%0A%20%20%20%20%23%20Making%20data%20frames%20looking%20like%20in%20Julia%20and%20Pluto%20(first%205%20rows%20%2B%20last%20row)%0A%20%20%20%20def%20preview(df%2C%20n%3D5)%3A%0A%20%20%20%20%20%20%20%20if%20len(df)%20%3C%3D%20n%20%2B%201%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20return%20df%0A%0A%20%20%20%20%20%20%20%20ellipsis%20%3D%20pd.DataFrame(%0A%20%20%20%20%20%20%20%20%20%20%20%20%5B%5B%22...%22%5D%20*%20df.shape%5B1%5D%5D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20columns%3Ddf.columns%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20index%3D%5B%22%E2%80%A6%22%5D%2C%0A%20%20%20%20%20%20%20%20)%0A%0A%20%20%20%20%20%20%20%20return%20pd.concat(%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20df.head(n)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20ellipsis%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20df.tail(1)%2C%0A%20%20%20%20%20%20%20%20%5D)%0A%20%20%20%20return%20(preview%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20%23%20Global%20CSS%20for%20kbd%20elements%20throughout%20the%20notebook%0A%20%20%20%20mo.Html(%22%22%22%0A%20%20%20%20%20%20%20%20%3Cstyle%3E%0A%20%20%20%20%20%20%20%20%20%20%20%20kbd%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20background-color%3A%20%23505050%20!important%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20color%3A%20%23fff%20!important%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20padding%3A%203px%206px%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20border-radius%3A%204px%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20font-family%3A%20monospace%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20font-size%3A%200.9em%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20border%3A%200px%20solid%20%23666%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%3C%2Fstyle%3E%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_()%3A%0A%20%20%20%20%23background-color%3A%20%23546ccc%20!important%3B%20%23%20A%20color%20that%20looks%20goog%20on%20white%20theme%3B%0A%20%20%20%20return%0A%0A%0Aif%20__name__%20%3D%3D%20%22__main__%22%3A%0A%20%20%20%20app.run()%0A
5a5b712c8bf28c7d46c1cdf67529b696